home *** CD-ROM | disk | FTP | other *** search
/ QuickTime 2.0 Developer Kit / QuickTime 2.0 Developer Kit.iso / mac / MAC / System Extensions / MIDI Management Tools 2.0.2 / Interfaces & Glue / MIDI.p < prev    next >
Encoding:
Text File  |  1993-06-10  |  12.3 KB  |  388 lines  |  [TEXT/MPS ]

  1. UNIT MIDI;
  2.  
  3. {
  4.   MIDI.p
  5.  
  6.   This file contains the pascal-language interface for the MIDI Manager.
  7.  
  8.   Author: John Worthington, Don Marsh, Mark Lentczner
  9.   Copyright © 1988-90, Apple Computer, Inc.
  10.   All Rights Reserved
  11. }
  12.  
  13.  
  14. INTERFACE
  15.  
  16. USES 
  17.     MemTypes,
  18.     QuickDraw,
  19.     OSIntf;
  20.                 
  21.  
  22. CONST
  23.  
  24.     midiToolNum          = 4;         {tool number of MIDI Manager for SndDispVersion call}
  25.  
  26.     midiMaxNameLen        = 31;        {maximum number of characters in port and client names}
  27.  
  28.  
  29.     {Time formats}
  30.  
  31.     midiFormatMSec        = 0;        {milliseconds}
  32.     midiFormatBeats        = 1;        {beats}
  33.     midiFormat24fpsBit    = 2;        {24 frames/sec.}
  34.     midiFormat25fpsBit    = 3;        {25 frames/sec.}
  35.     midiFormat30fpsDBit    = 4;        {30 frames/sec. drop-frame}
  36.     midiFormat30fpsBit    = 5;        {30 frames/sec.}
  37.     midiFormat24fpsQF    = 6;        {24 frames/sec.longInt format}
  38.     midiFormat25fpsQF    = 7;        {25 frames/sec.longInt format}
  39.     midiFormat30fpsDQF    = 8;        {30 frames/sec. drop-frame longInt format}
  40.     midiFormat30fpsQF    = 9;        {30 frames/sec.longInt format}
  41.  
  42.     midiInternalSync    = 0;        {internal sync}
  43.     midiExternalSync    = 1;        {external sync}
  44.  
  45.  
  46.     {Port types}
  47.  
  48.     midiPortTypeTime    = 0;        {time port}
  49.     midiPortTypeInput    = 1;        {input port}
  50.     midiPortTypeOutput    = 2;        {output port}
  51.     midiPortTypeTimeInv    = 3;        {invisible time port}
  52.     midiPortInvisible    = $8000;    {add this to above to make ports invisible}
  53.     midiPortTypeMask    = $0007;    {AND with this to convert new port types to old,
  54.                                         ie. to strip property bits}
  55.  
  56.  
  57.     {OffsetTimes}
  58.  
  59.     midiGetEverything    = $7FFFFFFF;    {get all packets, regardless of time stamps}
  60.     midiGetNothing        = $80000000;    {get no packets, regardless of time stamps}
  61.     midiGetCurrent        = $00000000;    {get current packets only}
  62.                 
  63.  
  64.                 
  65.  
  66. {
  67.   MIDI data and messages are passed in MIDIPacket records (see below).
  68.   The first byte of every MIDIPacket contains a set of flags
  69.  
  70.   bits 0-1    00 = new MIDIPacket, not continued
  71.              01 = begining of continued MIDIPacket
  72.              10 = end of continued MIDIPacket
  73.              11 = continuation
  74.   bits 2-3  reserved
  75.  
  76.   bits 4-6    000 = packet contains MIDI data
  77.              001 = packet contains MIDI Manager message
  78.  
  79.   bit 7        0 = MIDIPacket has valid stamp
  80.               1 = stamp with current clock
  81. }
  82.  
  83.     midiContMask        = $03;
  84.     midiNoCont            = $00;
  85.     midiStartCont        = $01;
  86.     midiMidCont            = $03;
  87.     midiEndCont            = $02;
  88.  
  89.     midiTypeMask        = $70;
  90.     midiMsgType            = $00;
  91.     midiMgrType            = $10;
  92.  
  93.     midiTimeStampCurrent    = $80;
  94.     midiTimeStampValid        = $00;
  95.     midiTimeStampMask        = $80;
  96.  
  97.  
  98.     {MIDI Manager MIDIPacket command words (the first word in the 
  99.      data field for midiMgrType messages) }
  100.  
  101.     midiOverflowErr        = $0001;
  102.     midiSCCErr            = $0002;
  103.     midiPacketErr        = $0003;
  104.     midiMaxErr            = $00FF;            {all command words less than this value}
  105.                                             {  are error indicators}
  106.  
  107.  
  108.     {valid results to be returned by readHooks}
  109.     
  110.     midiKeepPacket        = 0;
  111.     midiMorePacket        = 1;
  112.     midiNoMorePacket    = 2;
  113.     
  114.  
  115. {
  116.   Errors:
  117. }
  118.  
  119.     midiNoClientErr        = -250;    {no client with that ID found}
  120.     midiNoPortErr        = -251;    {no port with that ID found}
  121.     midiTooManyPortsErr    = -252;    {too many ports already installed in the system}
  122.     midiTooManyConsErr    = -253;    {too many connections made}
  123.     midiVConnectErr        = -254;    {pending virtual connection created}
  124.     midiVConnectMade    = -255;    {pending virtual connection resolved}
  125.     midiVConnectRmvd    = -256;    {pending virtual connection removed}
  126.     midiNoConErr        = -257;    {no connection exists between specified ports}
  127.     midiWriteErr        = -258;    {MIDIWritePacket couldn't write to all connected ports}
  128.     midiNameLenErr        = -259;    {name supplied is longer than 31 characters}
  129.     midiDupIDErr        = -260;    {duplicate client ID}
  130.     midiInvalidCmdErr    = -261;    {command not supported for port type}
  131.  
  132.  
  133.  
  134. {
  135.   Driver calls:
  136. }
  137.  
  138.     midiOpenDriver        = 1;
  139.     midiCloseDriver        = 2;
  140.  
  141.  
  142. {
  143.   All notes off:
  144. }
  145.  
  146.     mdvrAbortNotesOff    = 0;    { abort previous mdvrNotesOff request }
  147.     mdvrChanNotesOff    = 1;    { generate channel note off messages }
  148.     mdvrAllNotesOff        = 2;    { generate all note off messages }
  149.  
  150.     mdvrStopOut            = 0;    { stop calling the MDVROut temporarily } 
  151.     mdvrStartOut        = 1;    { resume calling MDVROut }
  152.  
  153. TYPE
  154.  
  155. {
  156.   MIDI data and other messages are read and written in packets:
  157. }
  158.  
  159.     MIDIPacket        = PACKED RECORD
  160.                         flags            : BYTE;
  161.                         len                : BYTE;
  162.                         tStamp            : LONGINT;
  163.                         data            : PACKED ARRAY [0..248] OF BYTE;
  164.                     END;
  165.     MIDIPacketPtr    = ^ MIDIPacket;
  166.  
  167.  
  168. {
  169.   Clocks:
  170. }
  171.  
  172.     MIDIClkInfo        = RECORD
  173.                         sync            : INTEGER;        {synchronization internal/external}
  174.                         curTime            : LONGINT;        {current value of port's clock}
  175.                         format            : INTEGER;        {time code format}
  176.                     END;
  177.  
  178.  
  179.  
  180. {
  181.   port information
  182. }
  183.  
  184.     MIDIIDRec        = RECORD
  185.                         clientID        : OSType;
  186.                         portID            : OSType;
  187.                     END;
  188.                     
  189.     MIDIPortInfo    = RECORD
  190.                         portType        : INTEGER;        {type of port}
  191.                         timeBase        : MIDIIDRec;    {MIDIIDRec for time base}
  192.                         numConnects        : INTEGER;        {number of connections}
  193.                         cList            : ARRAY [1..100] OF MIDIIDRec
  194.                                                         {the connections}
  195.                     END;
  196.  
  197.     MIDIPortInfoPtr    = ^ MIDIPortInfo;
  198.     MIDIPortInfoHdl    = ^ MIDIPortInfoPtr;
  199.  
  200.  
  201.     MIDIPortParams    = RECORD
  202.                         portID            : OSType;        {ID of port, unique within client}
  203.                         portType        : INTEGER;        {Type of port - input, output, time, etc.}
  204.                         timeBase        : INTEGER;        {refnum of time base, 0 if none}
  205.                         offsetTime        : LONGINT;        {offset for current time stamps}
  206.                         readHook        : Ptr;            {routine to call when input data is valid}
  207.                         refCon            : LONGINT;        {refcon for port (for client use)}
  208.                         initClock        : MIDIClkInfo;    {initial info for a time base}
  209.                         name            : Str255;        {name of the port}
  210.                     END;
  211.  
  212.     MIDIPortParamsPtr    = ^ MIDIPortParams;
  213.  
  214.  
  215. {
  216.  ID List
  217. }
  218.     MIDIIDList        = RECORD
  219.                         numIDs             : INTEGER;
  220.                         list             : ARRAY [1..100] of OSTYPE;
  221.                     END;
  222.     MIDIIDListPtr    = ^ MIDIIDList;
  223.     MIDIIDListHdl    = ^ MIDIIDListPtr;
  224.  
  225. { MDVR record declarations }
  226.  
  227.     MDVRInCtlRec = RECORD
  228.         timeCodeClock    : Integer;    { refnum of time base for time code }
  229.         timeCodeFormat    : Integer;    { format of time code output }
  230.         readProc    : ProcPtr;    { proc to call with input characters }
  231.         commProc    : ProcPtr;    { proc to call for handshaking }
  232.         refCon    : LONGINT;    { refCon passed to readProc, commProc }
  233.     END;
  234.  
  235.     MDVRInCtlPtr = ^MDVRInCtlRec;
  236.  
  237.     MDVROutCtlRec = RECORD
  238.         timeCodeClock    : Integer;    { time base driven by time code }
  239.         timeCodeFormat    : Integer;    { format of time code to listen to }
  240.         timeCodeProc    : ProcPtr;    { proc called on time code fmt change }
  241.         commProc    : ProcPtr;    { proc to call for handshaking }
  242.         refCon    : LONGINT;    { refCon passed to timeCodeProc }
  243.         timeCodeFilter    : Boolean;    { filter time code if true }
  244.         midiMsgTicks    : LONGINT;    { value of Ticks when MIDI msg rcvd }
  245.         timeCodeTicks    : LONGINT;    { value of Ticks when time code rcvd }
  246.     END;
  247.  
  248.     MDVROutCtlPtr = ^MDVROutCtlRec;
  249.     
  250. MDVRPtr = Ptr;
  251.     
  252.     
  253.  
  254. { Prototype Declarations for readHooks and timeProcs }
  255. {
  256. FUNCTION myReadHook(myPacket : MIDIPacketPtr; myRefCon : LONGINT) : INTEGER;
  257.  
  258. PROCEDURE myTimeProc(curTime : LONGINT; myRefCon : LONGINT);
  259.  
  260. PROCEDURE connectionProc(refnum:INTEGER; refCon:LONGINT;
  261.     portType:INTEGER; clientID:OSType; portID:OSType;
  262.     connect:BOOLEAN; direction:INTEGER);
  263.  
  264. }
  265.  
  266. { Prototype Declarations for driver routines }
  267. {
  268. FUNCTION CommProc (refnum : INTEGER; request: INTEGER; refCon: LONGINT): LONGINT;
  269. PROCEDURE TimeCodeProc( refnum : INTEGER; newFormat : INTEGER; refCon : LONGINT);
  270. PROCEDURE ReadProc (char: ^midiChars, length INTEGER; refCon LONGINT);
  271. }
  272.  
  273.  
  274. { MIDI Manager Routines }                
  275.  
  276. FUNCTION SndDispVersion(toolnum : INTEGER) : LONGINT;
  277.  
  278. FUNCTION MIDISignIn(ID : OSTYPE; refCon : longint; icon : Handle; name : STR255) : OSErr;
  279.     INLINE $203C,4,midiToolNum,$A800;
  280. PROCEDURE MIDISignOut(ID :OSTYPE);
  281.     INLINE $203C,8,midiToolNum,$A800;
  282. FUNCTION MIDIGetClients : MIDIIDListHdl;
  283.     INLINE $203C,12,midiToolNum,$A800;
  284. PROCEDURE MIDIGetClientName(ID : OSTYPE; VAR name : STR255);
  285.     INLINE $203C,16,midiToolNum,$A800;
  286. PROCEDURE MIDISetClientName(ID : OSTYPE; name : STR255);
  287.     INLINE $203C,20,midiToolNum,$A800;
  288. FUNCTION MIDIGetPorts(clientID : OSTYPE) : MIDIIDListHdl;
  289.     INLINE $203C,24,midiToolNum,$A800;
  290. FUNCTION MIDIAddPort(clientID: OSTYPE; BufSize : integer; 
  291.                         var refnum : integer; init : MIDIPortParamsPtr) : OSErr;
  292.     INLINE $203C,28,midiToolNum,$A800;
  293. FUNCTION MIDIGetPortInfo(clientID : OSTYPE; portID : OSTYPE) : MIDIPortInfoHdl;
  294.     INLINE $203C,32,midiToolNum,$A800;
  295. FUNCTION MIDIConnectData(srcClID, srcPortID, dstClID, dstPortID : OSTYPE) : OSErr;
  296.     INLINE $203C,36,midiToolNum,$A800;
  297. FUNCTION MIDIUnConnectData(srcClID, srcPortID, dstClID, dstPortID : OSTYPE) : OSErr;
  298.     INLINE $203C,40,midiToolNum,$A800;
  299. FUNCTION MIDIConnectTime(srcClID, srcPortID, dstClID, dstPortID : OSTYPE) : OSErr;
  300.     INLINE $203C,44,midiToolNum,$A800;
  301. FUNCTION MIDIUnConnectTime(srcClID, srcPortID, dstClID, dstPortID : OSTYPE) : OSErr;
  302.     INLINE $203C,48,midiToolNum,$A800;
  303. PROCEDURE MIDIFlush(refnum : integer);
  304.     INLINE $203C,52,midiToolNum,$A800;
  305. FUNCTION MIDIGetReadHook(refnum : integer) : ProcPtr;
  306.     INLINE $203C,56,midiToolNum,$A800;
  307. PROCEDURE MIDISetReadHook(refnum : integer; hook : ProcPtr);
  308.     INLINE $203C,60,midiToolNum,$A800;
  309. PROCEDURE MIDIGetPortName(client : OSTYPE; port : OSTYPE; VAR name : STR255);
  310.     INLINE $203C,64,midiToolNum,$A800;
  311. PROCEDURE MIDISetPortName(client : OSTYPE; port : OSTYPE; name : STR255);
  312.     INLINE $203C,68,midiToolNum,$A800;
  313. PROCEDURE MIDIWakeUp(refnum : integer; time : longint; period : longint; timeProc : ProcPtr);
  314.     INLINE $203C,72,midiToolNum,$A800;
  315. PROCEDURE MIDIRemovePort(refnum : integer);
  316.     INLINE $203C,76,midiToolNum,$A800;
  317. FUNCTION MIDIGetSync(refnum : integer) : integer;
  318.     INLINE $203C,80,midiToolNum,$A800;
  319. PROCEDURE MIDISetSync(refnum : integer; sync : integer);
  320.     INLINE $203C,84,midiToolNum,$A800;
  321. FUNCTION MIDIGetCurTime(refnum : integer) : longint;
  322.     INLINE $203C,88,midiToolNum,$A800;
  323. PROCEDURE MIDISetCurTime(refnum : integer; time : longint);
  324.     INLINE $203C,92,midiToolNum,$A800;
  325. PROCEDURE MIDIStartTime(refnum : integer);
  326.     INLINE $203C,96,midiToolNum,$A800;
  327. PROCEDURE MIDIStopTime(refnum : integer);
  328.     INLINE $203C,100,midiToolNum,$A800;
  329. PROCEDURE MIDIPoll(refnum : integer; offsetTime : longint);
  330.     INLINE $203C,104,midiToolNum,$A800;
  331. FUNCTION MIDIWritePacket(refnum : integer; packet : MIDIPacketPtr) : OSErr; 
  332.     INLINE $203C,108,midiToolNum,$A800;
  333. FUNCTION MIDIWorldChanged(clientID : OSTYPE) : BOOLEAN;
  334.     INLINE $203C,112,midiToolNum,$A800;
  335. FUNCTION MIDIGetOffsetTime(refnum : integer) : longint;
  336.     INLINE $203C,116,midiToolNum,$A800;
  337. PROCEDURE MIDISetOffsetTime(refnum : integer; offsetTime : longint);
  338.     INLINE $203C,120,midiToolNum,$A800;
  339. FUNCTION MIDIConvertTime(srcformat : integer; dstformat : integer; time : longint) : longint;
  340.     INLINE $203C,124,midiToolNum,$A800;
  341. FUNCTION MIDIGetRefCon(refnum : integer) : longint;
  342.     INLINE $203C,128,midiToolNum,$A800;
  343. PROCEDURE MIDISetRefCon(refnum : integer; refCon : longint);
  344.     INLINE $203C,132,midiToolNum,$A800;
  345. FUNCTION MIDIGetClRefCon(clientID : OSTYPE) : longint;
  346.     INLINE $203C,136,midiToolNum,$A800;
  347. PROCEDURE MIDISetClRefCon(clientID : OSTYPE; refCon : longint);
  348.     INLINE $203C,140,midiToolNum,$A800;
  349. FUNCTION MIDIGetTCFormat(refnum : integer) : integer;
  350.     INLINE $203C,144,midiToolNum,$A800;
  351. PROCEDURE MIDISetTCFormat(refnum : integer; format : integer);
  352.     INLINE $203C,148,midiToolNum,$A800;
  353. PROCEDURE MIDISetRunRate(refnum : integer; rate : integer; time : longint);
  354.     INLINE $203C,152,midiToolNum,$A800;
  355. FUNCTION MIDIGetClientIcon(ID : OSTYPE) : Handle;
  356.     INLINE $203C,156,midiToolNum,$A800;
  357. FUNCTION MIDICallAddress(callNum : integer): ProcPtr;
  358.     INLINE $203C,164,midiToolNum,$A800;
  359. PROCEDURE MIDIsetConnectionProc(refnum: integer; connectionProc: ProcPtr; refCon : longint);
  360.     INLINE $203C,168,midiToolNum,$A800;
  361. PROCEDURE MIDIGetConnectionProc(refnum: integer; VAR connectionProc: ProcPtr; VAR refCon : longint);
  362.     INLINE $203C,172,midiToolNum,$A800;
  363. PROCEDURE MIDIDiscardPacket(refnum: integer; packet: MIDIPacketPtr);
  364.     INLINE $203C,176,midiToolNum,$A800;
  365. FUNCTION MDVRSignIn(clientID : OSTYPE; refCon: longint; icon: Handle; name : Str255): OSErr;
  366.     INLINE $203C,180,midiToolNum,$A800;
  367. PROCEDURE MDVRSignOut(clientID : OSTYPE);
  368.     INLINE $203C,184,midiToolNum,$A800;
  369. FUNCTION MDVROpen(portType : integer; refnum : integer): MDVRPtr;
  370.     INLINE $203C,188,midiToolNum,$A800;
  371. PROCEDURE MDVRClose(portPtr: MDVRPtr);
  372.     INLINE $203C,192,midiToolNum,$A800;
  373. PROCEDURE MDVRControlIn(portPtr: MDVRPtr; inputCtl: MDVRPtr);
  374.     INLINE $203C,196,midiToolNum,$A800;
  375. PROCEDURE MDVRControlOut(portPtr: MDVRPtr; outputCtl: MDVROutCtlPtr);
  376.     INLINE $203C,200,midiToolNum,$A800;
  377. PROCEDURE MDVRIn(portPtr: MDVRPtr);
  378.     INLINE $203C,204,midiToolNum,$A800;
  379. PROCEDURE MDVROut(portPtr: MDVRPtr; dataPtr : Ptr; length : integer);
  380.     INLINE $203C,208,midiToolNum,$A800;
  381. PROCEDURE MDVRNotesOff(portPtr: MDVRPtr; mode : integer);
  382.     INLINE $203C,212,midiToolNum,$A800;
  383.  
  384.  
  385. IMPLEMENTATION
  386.  
  387. END.
  388.